﻿<UserControl x:Class="WpfRcp.Views.Controls.JobsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:Helpers="clr-namespace:WpfRcp.Helpers"
             xmlns:Threading="clr-namespace:WpfRcp.Core.Threading;assembly=WpfRcp.Core"
             xmlns:Windows="clr-namespace:WpfRcp.Views.Windows"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">

    <UserControl.Resources>
        <Windows:CancelEnableabilityConverter x:Key="cancelEnableabilityConverter" />
        <Windows:DateTimeValueConverter x:Key="dateTimeValueConverter" />
        <Windows:JobStateValueConverter x:Key="jobStateValueConverter" />
    </UserControl.Resources>
    
    <Grid>
        <!--ASYNC OPERATIONS LIST-->
        <ListView ItemsSource="{Binding Source={x:Static Threading:Job.AllJobs}}">
            <ListView.View>
                <GridView ColumnHeaderContainerStyle="{StaticResource GridViewColumnHeaderStyle}">
                    <GridViewColumn Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[Message]}" DisplayMemberBinding="{Binding Name}" Width="200" />
                    <GridViewColumn Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[StartTime]}" DisplayMemberBinding="{Binding StartTime, Converter={StaticResource dateTimeValueConverter}}" Width="140" />
                    <GridViewColumn Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[EndTime]}" DisplayMemberBinding="{Binding EndTime, Converter={StaticResource dateTimeValueConverter}}" Width="140" />
                    <GridViewColumn Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[TimeElapsed]}" DisplayMemberBinding="{Binding TimeElapsed}" Width="140" />
                    <GridViewColumn Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[State]}" DisplayMemberBinding="{Binding State, Converter={StaticResource jobStateValueConverter}}" Width="120" />
                </GridView>
            </ListView.View>

            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="{Binding Source={x:Static Helpers:ResHelper.Instance}, Path=Resource[Cancel]}" Command="{Binding CancelOperationCommand}" CommandParameter="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem}"
                              IsEnabled="{Binding RelativeSource={RelativeSource AncestorType=ContextMenu}, Path=PlacementTarget.SelectedItem, Converter={StaticResource cancelEnableabilityConverter}}">
                    </MenuItem>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
    </Grid>
</UserControl>
